﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DAL
{
    public class ThamSoDAO
    {
        public int Update(DTO.ThamSoDTO dto)
        {
            int r = -1;
            try
            {
                List<System.Data.SqlClient.SqlParameter> prs =
                    new List<System.Data.SqlClient.SqlParameter>();
                prs.Add(new System.Data.SqlClient.SqlParameter("@NhapToiThieu", dto.NhapToiThieu));
                prs.Add(new System.Data.SqlClient.SqlParameter("@TonToiDa", dto.TonToiDa));
                prs.Add(new System.Data.SqlClient.SqlParameter("@TonToiThieu", dto.TonToiThieu));
                prs.Add(new System.Data.SqlClient.SqlParameter("@NoToiDa", dto.NoToiDa));
                prs.Add(new System.Data.SqlClient.SqlParameter("@QD4", dto.QD4));
                r = DAL.sqlHelper.ExecuteNoneQuery("ThamSo_UpdateAll", prs);
                return r;
            }
            catch (System.Exception ex)
            {
                throw new System.Exception("ThamSoDAO::Update failed " +
                ex.Message);
            }
            finally
            {
            }
        }

        public DTO.ThamSoDTO Select()
        {
            DTO.ThamSoDTO dto = new DTO.ThamSoDTO();
            try
            {
                List<System.Data.SqlClient.SqlParameter> prs =
                    new List<System.Data.SqlClient.SqlParameter>();
                System.Data.DataTable dt =
                    DAL.sqlHelper.ExecuteQuery("ThamSo_SelectAll", prs);
                if (dt.Rows.Count > 0)
                {
                    dto.NhapToiThieu = int.Parse(dt.Rows[0]["NhapToiThieu"].ToString());
                    dto.TonToiDa = int.Parse(dt.Rows[0]["TonToiDa"].ToString());
                    dto.TonToiThieu = int.Parse(dt.Rows[0]["TonToiThieu"].ToString());
                    dto.NoToiDa = float.Parse(dt.Rows[0]["NoToiDa"].ToString());
                    dto.QD4 = int.Parse(dt.Rows[0]["QD4"].ToString());
                }
                return dto;
            }
            catch (System.Exception ex)
            {
                throw new System.Exception("ThamSoDAO::Select failed " +
                ex.Message);
            }
            finally
            {
            }
        }
    }
}
